package com.atguigu.juc.study.chapter08.aba;

import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * @author : leimingchao
 * @date Date : 2022年06月14日 22:57
 */
public class AtomicStampedDemo {

    public static void main(String[] args) {

        Book book = new Book(1, "javaBook");

        AtomicStampedReference<Book> atomicStampedReference = new AtomicStampedReference<>(book, 1);

        System.out.println(atomicStampedReference.getReference() + "\t" + atomicStampedReference.getStamp());

        Book mysql = new Book(2, "mysqlBook");

        boolean b;
        b = atomicStampedReference.compareAndSet(book, mysql, atomicStampedReference.getStamp(), atomicStampedReference.getStamp() + 1);

        System.out.println(b + "\t" +atomicStampedReference.getReference() + "\t" + atomicStampedReference.getStamp());

        b = atomicStampedReference.compareAndSet(mysql, book, atomicStampedReference.getStamp(), atomicStampedReference.getStamp() + 1);

        System.out.println(b + "\t" +atomicStampedReference.getReference() + "\t" + atomicStampedReference.getStamp());
    }
}
